Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for setting the minimum supported WP version from the command line #1094

Merged
merged 1 commit into from
Aug 7, 2017

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Aug 7, 2017

This PR addresses the comments made here: #826 (comment)

This change allows for setting the minimum_supported_version property for all three WP.Deprecated... sniffs in one go, either via the command-line or by setting a config variable in a custom ruleset.

As this config variable is no longer directly related to a sniff, I've chosen to make the name slightly more specific/descriptive: minimum_supported_wp_version <= note the _wp_.

Usage:

phpcs . --standard=WordPress --runtime-set minimum_supported_wp_version 4.5

or in a ruleset:

<config name="minimum_supported_wp_version" value="4.5"/>

The above one liner can replace the custom property which would otherwise need to be set for all three sniffs individually.

Overrule order:

  1. Value passed via the command line
  2. <config> property in the ruleset
  3. Individual sniff <property>'s set via the ruleset
  4. Default value

Simplest way to test this is by running PHPCS over the WP.DeprecatedParameter sniff unit tests:

phpcs -p -s ./WordPress/Tests/DeprecatedParametersUnitTest.inc --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameters

phpcs -p -s ./WordPress/Tests/DeprecatedParametersUnitTest.inc --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameters --runtime-set minimum_supported_wp_version 4.8

phpcs -p -s ./WordPress/Tests/DeprecatedParametersUnitTest.inc --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameters --runtime-set minimum_supported_wp_version 3.8

Additional notes:

  • I've moved the $custom_test_class_whitelist property up in the WordPress\Sniff class, so both public properties are now at the top of the file.

To do once this PR is merged:

  • Update the customizable properties wiki page with information about this feature

This change allows for setting the `minimum_supported_version` property for all three `WP.Deprecated...` sniffs in one go, either via the command-line or by setting a config variable in a custom ruleset.

As this config variable is no longer directly related to a sniff, I've chosen to make the name slightly more specific/descriptive: `minimum_supported_wp_version` <= note the `_wp_`.

Usage:
```bash
phpcs . --standard=WordPress --runtime-set minimum_supported_wp_version 4.5
```

or in a ruleset:
```xml
<config name="minimum_supported_wp_version" value="4.5"/>
```

The above one liner can replace the custom property which would otherwise need to be set for all three sniffs individually.

Overrule order:
1. Value passed via the command line
2. `<config>` property in the ruleset
3. Individual sniff `<property>`'s set via the ruleset
4. Default value

Simplest way to test this is by running PHPCS over the `WP.DeprecatedParameters` sniff unit tests:
```bash
phpcs -p -s ./WordPress/Tests/DeprecatedParametersUnitTest.inc --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameters

phpcs -p -s ./WordPress/Tests/DeprecatedParametersUnitTest.inc --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameters --runtime-set minimum_supported_wp_version 4.8

phpcs -p -s ./WordPress/Tests/DeprecatedParametersUnitTest.inc --standard=WordPress --sniffs=WordPress.WP.DeprecatedParameters --runtime-set minimum_supported_wp_version 3.8
```

Additional notes:
* I've moved the `$custom_test_class_whitelist` property up in the `WordPress\Sniff` class, so both `public` properties are now at the top of the file.
@jrfnl jrfnl added this to the 0.14.0 milestone Aug 7, 2017
@jrfnl jrfnl force-pushed the feature/min-wp-version-via-command-line-config branch from 4abd827 to 80442d2 Compare August 7, 2017 06:35
@grappler
Copy link
Member

grappler commented Aug 7, 2017

This breaks backwards compatibility? Just checking so that I know to update my custom rulesets.

@jrfnl
Copy link
Member Author

jrfnl commented Aug 7, 2017

This breaks backwards compatibility? Just checking so that I know to update my custom rulesets.

No, it does not break backwards compatibility, the custom properties are still supported as they were. You can just overrule them now in one go using the <config> setting / --runtime-set or replace them with <config>, but you don't need to.

@JDGrimes JDGrimes merged commit 4a97ddd into develop Aug 7, 2017
@JDGrimes JDGrimes deleted the feature/min-wp-version-via-command-line-config branch August 7, 2017 14:10
@jrfnl
Copy link
Member Author

jrfnl commented Aug 18, 2017

FYI: Info about the effect of this PR has now been added to the wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants